//
//  CZBaseViewController.swift
//  swift微博01
//
//  Created by 张文文 on 15/12/16.
//  Copyright © 2015年 张文文. All rights reserved.
//

import UIKit

class CZBaseViewController: UITableViewController {

    var userLogin = false
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    //设置访客视图
    func setupVisitorView(){
        //设置view
        view = visitorView
        
        //设置代理
        visitorView.delegate = self
        //判断当前时哪个控制器
        if self is CZHomeViewController{
        
            visitorView.rotationAnimation()
            //监听应用进入和退出后台
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }else if self is CZMessageViewController{
        
            visitorView.setupInfo("visitordiscover_image_message", message: "登录后 别人可以评论你的微博")
        }else if self is CZDiscoveryViewController{
        
            visitorView.setupInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is CZProfileViewController{
        
            visitorView.setupInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginClick")
    }
    private lazy var visitorView : CZVisitorView = CZVisitorView()
    //进入后台会调用
    func didEnterBackground() {
    
        //暂停核心动画
        visitorView.pauseAnimation()
    }
    //进入应用程序
    func didBecomeActive() {
    
        //开始核心动画
        visitorView.resumeAnimation()
        
    }
}

extension CZBaseViewController : CZVisitorViewDelegate{

    //实现代理方法
    func visitorViewLoginClick() {
        
    }
}


